# Example input file to test automatic differentiation with
# a cube mesh from Gmsh.
# Initially based on
#   moose/modules/tensor_mechanics/
#      test/tests/ad_finite_elastic/finite_elastic.i
#      examples/hyper_elastic_test.i
#   spider/neohookean_example.i

# Status: testing

[Mesh]
  type = GeneratedMesh
  dim = 3
  nx = 5
  ny = 5
  nz = 5
  use_displaced_mesh = false
[]

[GlobalParams]
  displacements = 'disp_x disp_y disp_z'
[]

[Variables]
  [./disp_x]
  [../]
  [./disp_y]
  [../]
  [./disp_z]
  [../]
[]

[Functions]
  [./top_displacement]
    type = ParsedFunction
    value = t
  [../]
[]

[BCs]
  [./symmy]
    type = PresetBC
    variable = 'disp_y'
    boundary = bottom
    value = 0
  [../]
  [./symmx]
    type = PresetBC
    variable = 'disp_x'
    boundary = left
    value = 0
  [../]
  [./symmz]
    type = PresetBC
    variable = 'disp_z'
    boundary = back
    value = 0
  [../]
  # [./tdisp]
  #   type = PresetBC
  #   variable = 'disp_z'
  #   boundary = front
  #   value = 0.1
  # [../]
  [./pull]
      # Make displacement equal to time (end_time = 1; see below)
      function = '0.5*t'       # = \Delta{l} ==> stretch = 1.5t
      type = FunctionPresetBC
      variable = disp_z
      boundary = front
  [../]
[]

[ADKernels]
  [./stress_x]
    type = ADStressDivergenceTensors
    component = 0
    variable = disp_x
    # use_displaced_mesh = true
  [../]
  [./stress_y]
    type = ADStressDivergenceTensors
    component = 1
    variable = disp_y
    # use_displaced_mesh = true
  [../]
  [./stress_z]
    type = ADStressDivergenceTensors
    component = 2
    variable = disp_z
    # use_displaced_mesh = true
  [../]
[]

[Materials]
[]

[ADMaterials]
  [./rubber_elasticity]
    # This elasticity tensor has hard-coded values for now
    type = ComputeElasticityTensorNeohookean
    # # lambda = 1.2e7
    # # shear_modulus = 1.2e7
    # youngs_modulus = 1
    # poissons_ratio = 0.45 # the closer this gets to 0.5 the worse the problem becomes
  [../]
  [./strain]
    # type = ADComputeIncrementalSmallStrain
    type = ADComputeGreenLagrangeStrain
  [../]
  [./stress]
    type = ADComputeLinearElasticStress
    # type = ADComputeFiniteStrainElasticStress
  [../]
[]

[Preconditioning]
  [./smp]
    type = SMP
    full = true
  [../]
[]

[Executioner]
  type = Transient
  end_time = 1
  num_steps = 10
  # dtmin = 0.05

  solve_type = 'NEWTON'
  nl_abs_tol = 1e-10

  # petsc_options_iname = -pc_hypre_type
  # petsc_options_value = boomeramg

  #  num_steps = 1
[]

[AuxVariables]
  [./stress_xx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_xy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_xz]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_yx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_yy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_yz]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_zx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_zy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./stress_zz]
    family = MONOMIAL
    order = CONSTANT
  [../]

  [./strain_xx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_xy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_xz]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_yx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_yy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_yz]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_zx]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_zy]
    family = MONOMIAL
    order = CONSTANT
  [../]
  [./strain_zz]
    family = MONOMIAL
    order = CONSTANT
  [../]
[]

[AuxKernels]
  [./stress_xx]
    type = RankTwoAux
    variable = stress_xx
    rank_two_tensor = stress
    index_i = 0
    index_j = 0
  [../]
  [./stress_xy]
    type = RankTwoAux
    variable = stress_xy
    rank_two_tensor = stress
    index_i = 0
    index_j = 1
  [../]
  [./stress_xz]
    type = RankTwoAux
    variable = stress_xz
    rank_two_tensor = stress
    index_i = 0
    index_j = 2
  [../]
  [./stress_yx]
    type = RankTwoAux
    variable = stress_yx
    rank_two_tensor = stress
    index_i = 1
    index_j = 0
  [../]
  [./stress_yy]
    type = RankTwoAux
    variable = stress_yy
    rank_two_tensor = stress
    index_i = 1
    index_j = 1
  [../]
  [./stress_yz]
    type = RankTwoAux
    variable = stress_yz
    rank_two_tensor = stress
    index_i = 1
    index_j = 2
  [../]
  [./stress_zx]
    type = RankTwoAux
    variable = stress_zx
    rank_two_tensor = stress
    index_i = 2
    index_j = 0
  [../]
  [./stress_zy]
    type = RankTwoAux
    variable = stress_zy
    rank_two_tensor = stress
    index_i = 2
    index_j = 1
  [../]
  [./stress_zz]
    type = RankTwoAux
    variable = stress_zz
    rank_two_tensor = stress
    index_i = 2
    index_j = 2
  [../]

  [./strain_xx]
    type = RankTwoAux
    variable = strain_xx
    rank_two_tensor = total_strain
    index_i = 0
    index_j = 0
  [../]
  [./strain_xy]
    type = RankTwoAux
    variable = strain_xy
    rank_two_tensor = total_strain
    index_i = 0
    index_j = 1
  [../]
  [./strain_xz]
    type = RankTwoAux
    variable = strain_xz
    rank_two_tensor = total_strain
    index_i = 0
    index_j = 2
  [../]
  [./strain_yx]
    type = RankTwoAux
    variable = strain_yx
    rank_two_tensor = total_strain
    index_i = 1
    index_j = 0
  [../]
  [./strain_yy]
    type = RankTwoAux
    variable = strain_yy
    rank_two_tensor = total_strain
    index_i = 1
    index_j = 1
  [../]
  [./strain_yz]
    type = RankTwoAux
    variable = strain_yz
    rank_two_tensor = total_strain
    index_i = 1
    index_j = 2
  [../]
  [./strain_zx]
    type = RankTwoAux
    variable = strain_zx
    rank_two_tensor = total_strain
    index_i = 2
    index_j = 0
  [../]
  [./strain_zy]
    type = RankTwoAux
    variable = strain_zy
    rank_two_tensor = total_strain
    index_i = 2
    index_j = 1
  [../]
  [./strain_zz]
    type = RankTwoAux
    variable = strain_zz
    rank_two_tensor = total_strain
    index_i = 2
    index_j = 2
  [../]
[]

[Postprocessors]
  [./ave_stress_back_z]
    type = SideAverageValue
    variable = stress_zz
    boundary = back
  [../]
  [./ave_strain_front_z]
    type = SideAverageValue
    variable = strain_zz
    boundary = front
  [../]
[]

[Outputs]
  # Do not print data on screen (faster run)
  console = false
  perf_log = false

  execute_on = 'INITIAL TIMESTEP_END'
  exodus = true
  print_linear_residuals = false
[]
